import axios from "axios";
const service = axios.create({
    // process.env.NODE_ENV === 'development' 来判断是否开发环境
    // easy-mock服务挂了，暂时不使用了
    baseURL: "https://www.cfxs.work/api",
    //   timeout: 10000,
});

import { ElLoading } from "element-plus";
let loginNum = 0;

function startLogin() {
    loginNum = 1;
    if (loginNum == 1) {
        ElLoading.service();
    }
}

function endLogin() {
    loginNum = 0;
    if (loginNum == 0) {
        ElLoading.service().close();
    }
}
service.interceptors.request.use(
    (config) => {
        startLogin();
        config.headers.token = localStorage.getItem("token"),
            config.headers.tokenKey = localStorage.getItem("tokenKey")
        return config;
    },
    (error) => {
        console.log(error);
        return Promise.reject();
    }
);

service.interceptors.response.use(
    (response) => {
        if (response.status === 200) {
            endLogin();
            return response.data;
        } else {

            Promise.reject();
        }
    },
    (error) => {
        endLogin();
        console.log(error);
        return Promise.reject();
    }
);

export default service;